The present invention relates to loading resources in software applications, and more particularly, to detecting stale cached resources.
Software applications are often arranged as a suite of separate software components or resources. A main component or runtime environment will import resources from resource containers in order to operate as a complete software application. For example, an application may locate and access runtime functions stored in dynamic link libraries, or classes stored in class libraries. In order to locate such resources, a search path is used to indicate the location(s) of one or more such resource containers. For example, in the Java™ runtime environment a CLASSPATH environment variable can be used to define where classes can be found (Java is a trademark of Sun Microsystems Corp. in the United States, other countries, or both). The CLASSPATH is a list of locations (such as directories in a file system or fully qualified class library locations) and is used at runtime when a new class is loaded. Such search paths are ordered such that the application searches for required resources at a first location, before proceeding to subsequent locations in a sequential manner.
FIG. 1 is a block diagram of a resource processor 108 for loading resources from one or more resource containers 100 in the prior art. The resource processor 108 can be an application at runtime, or a runtime environment such as a Java virtual machine. The one or more resource containers 100 can be, for example, library files, class files, Java archive (jar) files or directories in a file system. Each of the resource containers 100 has a container identifier 102 such as the container name (e.g. a fully qualified jar file name or a fully qualified directory name). Within a resource container 100 can reside one or more resources 104. The one or more resources 104 can be, for example, class files or runtime libraries. Each of the resources 104 has an identifier, such as a class file name.
The resource processor 108 includes a resource loader 110 such as a class loader. The resource loader 110 is able to locate a resource 104 in a resource container 100 and load it into a memory of the computer system for use by the resource processor 108. The resource processor 108 further comprises a resource cache 112, which is a reserved section of memory in a computer system for storing one or more resources 116 which have been loaded from resource containers 100. The resource cache 112 can be a shared memory cache serving multiple resource loaders (not shown) or multiple resource processors (not shown). For example, the resource cache 112 can serve multiple Java class loader instances. The resource cache 112 can therefore exist outside the resource processor 108, such as on a separate computer system communicatively connected to the resource processor 108. The resources 116 stored in the resource cache 112 can be stored based on usage criteria, such as most frequently used resources. Each of the resources 116 in the resource cache 112 includes a resource identifier 118. It will be appreciated that the resources 116 stored in the resource cache 104 substantially reflect the resources 104 stored in resource containers 100 when they are loaded into the resource cache 112 by the resource loader 110. Thus, the resources 116 stored in the resource cache 112 are copies of the resources 104 stored in resource containers 100.
When searching for a particular resource the resource loader 110 uses a resource search path 114. The resource search path 114 includes an ordered container list 120 which is a list of resource containers. Each entry in the resource search path 114 includes an index 122 (the means by which the ordered container list 120 is ordered) and a container identifier 124 (corresponding to a container identifier 102 of one of the resource containers 100).
At runtime, the resource processor 108 requests that the resource loader 110 loads a particular resource identified by a resource identifier 106. The resource loader 110 first checks if the required resource is resident in the resource cache 112. If so, the resource can be quickly loaded from the resource cache 112. If not, the resource loader 110 locates the resource by searching sequentially through each of the resource containers in the ordered container list 120 of the resource search path 114. When a resource container is located with the required resource identifier 106 the resource loader 110 loads the required resource and may further add the loaded resource to the resource cache 112.